package io.kwdb.examples;

import io.kwdb.sdk.*;

public class TestIlpSpecialChars {
  public static void main(String[] args) {
    IlpEncoder encoder = new IlpEncoder();

    // Test 1: Tags with special chars
    Point point =
        Point.builder("sdk_bench")
            .tag("host", "value=with,special chars")
            .tag("region", "space test")
            .field("usage", 42.0)
            .timestamp(1696176000000000000L)
            .build();

    String ilpLine = encoder.encode(point);
    System.out.println("Encoded ILP: " + ilpLine);

    // Now test sending it
    Config config =
        Config.builder().host("127.0.0.1").httpPort(9091).transport(Config.Transport.ILP).build();

    try (IlpClient client = new IlpClient(config)) {
      System.out.println("\nSending ILP with special chars...");
      Status status = client.writeRaw(ilpLine);
      if (status.isOk()) {
        System.out.println("SUCCESS: Special chars worked!");
      } else {
        System.out.println("FAILED: " + status.getMessage());

        // Try a simpler version
        String simpleILP =
            "sdk_bench,host=special-test,region=us-west usage=42.0 1696176000000000000";
        System.out.println("\nTrying simpler ILP: " + simpleILP);
        status = client.writeRaw(simpleILP);
        if (status.isOk()) {
          System.out.println("SUCCESS: Simple ILP worked");
        } else {
          System.out.println("FAILED: " + status.getMessage());
        }
      }
    }
  }
}
